<?php
/*
    OpenLib
    Copyright (C) 2011  Michael Gukov, Pham Thi Thuy Duong, Pham Thi Thuy Duong

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


namespace App\Views\Index;

use Sun\Sun;
use Sun\Html\Form;

class Enter extends Main {

    public function __construct() {
        parent::__construct();
        $this->title = "Вход";
        $this->tab = "MenuEnter";
    }

    public function BodyScene() {
        $session = Sun::model("Session");
        if ($session->IsLogin()) {
            $p = $session->Profile();
            $type = array("READ" => "Reader", "LIB" => "Lib",  "ADMIN" => "Admin", 'TEACH' => 'Teach');
            header("Location: ?u=".$type[$p['sense']]);
        }
        else $this->AuthFormScene();
    }


    public function UserTypes() {
        $types = Sun::model("User")->UserTypes();
        $select = new Form\Select(array(
            'id' => 'type_id',
            'class' => 'Text'));

        foreach ($types as $type) {
            $select->AddOption($type[0], $type[1]);
        }
        return $select;
    }
}
